You've learnt about automation with Python and Selenium. It's your turn to get creative and automate some aspect of your life using what you have learnt.

This could be an aspect of your job, your schoolwork, your home, your chores. Think about your week and everything that you do on a regular basis, when do you feel like a robot? Which jobs do you find tedious and boring? Can it be automated?

Here are some stories for inspiration:

  • Automate an email to your boss to ask for a raise every 3 months. =)

  • Automate your lights so they switch on when your phone is within the radius of your house.

  • Automatically organise the files in your downloads folder based on file type.

  • Automate your gym class bookings.

  • Automate your library book renewals.

  • Automate your job.

  • Automate your home chores.

Personally, I had a job in a hospital where I had to arrange all the doctors' shifts in my department (normal day, long day, night shift). It would depend on when they wanted to take annual leave/vacation and the staffing requirements. It started out in an Excel spreadsheet, by the time I was done with it, it was fully automated with Python and doctors were able to view a live version of the rota to see when they can take time off. The code took an evening to write and it saves me 3 hours per week. (More time to watch Netflix and eat ice cream).

Once you're done with the assignment, let us know what you automated in your life and maybe it will inspire another student!

Questions for this assignment

Reflection Time:

This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.

Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?

Alberto Díez
Posted 1 month ago

Reflection Time:

This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.

Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?

My job as a researcher involves a lot of plotting from sequencing experiments, so I automated the plotting of whatever gene I wanted to display.


# Import necessary modules to read and plot
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    import numpy as np
    from google.colab import files
    
    # Open and reading the contents of genes_to_plot.txt and appending them to an iterable list
    with open("genes_to_plot.txt") as file:
        gene_list = [gene.strip() for gene in file.readlines()]
        gene_list_2 = [gene.capitalize() for gene in gene_list]
        print (f"The following genes will be plotted:\n{gene_list_2}")
    
    # Reading the .csv files and assigning them to a pandas DataFrame class
    df_duo = pd.read_csv("ApK_LsdK_DuovsApcK_Duo_deg.csv", sep = ";")
    df_ile = pd.read_csv("ApK_LsdK_IlevsApcK_Ile_deg.csv", sep = ";")
    
    for gene in gene_list_2:
    
      # Extracting full row from each gene and assigning it to a variable
      gene_row_duo = df_duo[df_duo.gene_name == gene]
      gene_row_ile = df_ile[df_ile.gene_name == gene]
    
      # Extract individual TPMs from row and add them to a list
      try:
        duo_single_ko_TPMs = []
        for n in range (1,7):
          duo_single_ko_TPMs.append(int(gene_row_duo[f"ApcK_D{n}_count"]))
      except TypeError:
        print(f"{gene} was not found on the .csv file, make sure you're using the right gene notation")
    
      try:
        duo_double_ko_TPMs = []
        for n in range (1,8):
          duo_double_ko_TPMs.append(int(gene_row_duo[f"ApcKLsd1K_D{n}_count"]))
      except TypeError:
        pass
    
      try:  
        ile_single_ko_TPMs = []
        for n in range (1,7):
          ile_single_ko_TPMs.append(int(gene_row_ile[f"ApcK_I{n}_count"]))
      except TypeError:
        pass
    
      try:
        ile_double_ko_TPMs = []
        for n in range (1,8):
          ile_double_ko_TPMs.append(int(gene_row_ile[f"ApcKLsd1K_I{n}_count"]))
      except TypeError:
        pass
    
    
      # Append an extra NaN value to the shorter lists (to avoid pandas error)
      duo_single_ko_TPMs.append(np.nan)
      ile_single_ko_TPMs.append(np.nan)
    
      # Get adjusted p-values of Duo and Ile comparisons and store them into a variable
      try:
        p_val_d = float(gene_row_duo["padj"])
        logfc_d = round(float(gene_row_duo["log2FoldChange"]), 2)
        p_val_i = float(gene_row_ile["padj"])
        logfc_i = round(float(gene_row_ile["log2FoldChange"]), 2)
      except TypeError:
        pass
    
      # Create a f-string containing all stat info that will be displayed as the x axis label
      try:
        stats = f"Duo ApcKO vs Duo ApcKO Lsd1 KO ---- p: {p_val_d} ---- logfc: {logfc_d} \nIle ApcKO vs Ile ApcKO Lsd1 KO ---- p: {p_val_i} ---- logfc: {logfc_i}"
      except NameError:
        pass
    
      # Define and create the DataFrames to plot 
      dataset = {
          "Duo ApcKO":duo_single_ko_TPMs,
          "Duo ApcKO Lsd1KO":duo_double_ko_TPMs,
          "Ile ApcKO":ile_single_ko_TPMs,
          "Ile ApcKO Lsd1KO":ile_double_ko_TPMs
      }
      try:
        df = pd.DataFrame(dataset)
    
        # Plot dataset with Seaborn
        plt.figure(figsize=(6,6), dpi=120)
        sns.swarmplot(data=df.melt(), x="variable", y="value", palette=['#00BFC4','#F8766D','#C77CFF','#7CAE00'], size = 8, hue = "variable")
        plt.legend().set_title(None)
        plt.title(label=gene, fontsize=20)
        plt.yticks(fontsize=14)
        plt.xticks(fontsize=14, rotation=45, horizontalalignment='right')
    
        # Plot the mean line
        sns.boxplot(showmeans=True,
                    meanline=True,
                    meanprops={'color': 'grey', 'ls': '-', 'lw': 2},
                    medianprops={'visible': False},
                    whiskerprops={'visible': False},
                    zorder=10,
                    x="variable",
                    y="value",
                    data=df.melt(),
                    showfliers=False,
                    showbox=False,
                    showcaps=False)
    
        # Reset the axis title after using boxplot to plot the mean line
        plt.ylabel('TPMs', fontsize=14)
        plt.xlabel(stats, color="grey", fontsize=10, loc="center")
    
    
        # Fill the NaN values in the DataFrame to find the max value using to_numpy().max()
        df.fillna(0, inplace=True)
    
        # Change the y axis limits in order to leave space to plot the p-value on top
        ax1 = plt.gca()
        y_top_limit = (df.to_numpy().max()) + (df.to_numpy().max())*0.1
        ax1.set_ylim([0, y_top_limit])
    
        # Hide top and right spines from the frame
        ax1.spines["right"].set_visible(False)
        ax1.spines["top"].set_visible(False)
    
        # Save the result as a vector image to the default content folder
        plt.savefig(f"{gene}_TPMs.svg", format = 'svg', dpi=300, bbox_inches='tight')
        plt.savefig(f"{gene}_TPMs.jpg", format = 'jpeg', dpi=300, bbox_inches='tight')
    
        # Next line automatically downloads a copy of the .svg plot
        files.download(f"{gene}_TPMs.svg")
        files.download(f"{gene}_TPMs.jpg")
    
        # Display the result
        plt.show()
      except ValueError:
        print(f"{gene} was not found on the .csv file and could not be plotted")

Give Feedback

What went well? What could be improved?

Meghashree.M
Posted 2 months ago

Reflection Time:

This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.

Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?

Easy

Give Feedback

What went well? What could be improved?

Abhimanue Sinha
Posted 7 hours ago

Reflection Time:

This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.

Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?

ddddddd

Give Feedback

What went well? What could be improved?